package com.shuoyue.ycgk.ui.mine.vip;

import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.BaseMvpActivity;
import com.shuoyue.ycgk.entity.VipPrice;
import com.shuoyue.ycgk.entity.VipPurchased;
import com.shuoyue.ycgk.utils.SizeUtil;
import com.shuoyue.ycgk.utils.SpacesItemDecoration;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MyBuyVipActivity extends BaseMvpActivity<VipCheckContract.Presenter>
        implements VipCheckContract.View {
    @BindView(R.id.page_title)
    TextView pageTitle;
    @BindView(R.id.recycler_view)
    RecyclerView mRecycleView;
    @BindView(R.id.refreshlayout)
    SmartRefreshLayout refreshlayout;

    MyVipAdapter vipAdapter;

    /**
     * 初始化layouy
     */
    @Override
    protected int getLayoutId() {
        return R.layout.activity_my_vip_list;
    }

    /**
     * 初始化布局
     */
    @Override
    protected void initView() {
        pageTitle.setText("我的会员");

        mRecycleView.setLayoutManager(new LinearLayoutManager(mContext));
        mRecycleView.addItemDecoration(new SpacesItemDecoration(SizeUtil.dip2px(mContext, 8), false));
        vipAdapter = new MyVipAdapter(null);
        mRecycleView.setAdapter(vipAdapter);
        registEmptyView(vipAdapter);
        refreshlayout.setOnRefreshListener(refreshLayout -> {
            mPresenter.getVipPurchased();
            refreshLayout.finishRefresh();
        });
    }

    @Override
    public void initData() {
        super.initData();
        mPresenter = new VipCheckContract.Presenter();
        mPresenter.attachView(this);
        mPresenter.getVipPurchased();
    }

    @OnClick({R.id.back, R.id.buy})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.buy:
                MyVipActivity.start(mContext, false);
                break;
        }
    }

    @Override
    public void isBuy(boolean isBuy) {

    }

    @Override
    public void setPurchased(List<VipPurchased> purchased) {
        vipAdapter.resetData(purchased);
    }
}
